
-- local map = {
--     {'meat','meat_01'},
--     {'meat_monster','monstermeat01'},
--     {'meat_small','meat_small01'},
--     {'drumstick','drumstick_01'},
--     {'fishmeat','fish_raw'}
-- }

local function setnewtile(x,y,z,tile)
    local tx,tz = TheWorld.Map:GetTileCoordsAtPoint(x,y,z)
    TheWorld.Map:SetTile(tx,tz,tile)
    TheWorld.Map:RebuildLayer(tile,tx,tz)
end

local function PlayerRemove(player, deletesession, migrationdata, readytoremove)
    if readytoremove then
        player:OnDespawn(migrationdata)
        if deletesession then
            DeleteUserSession(player)
        else
            player.migration = migrationdata ~= nil and {
                worldid = TheShard:GetShardId(),
                portalid = migrationdata.portalid,
                sessionid = TheWorld.meta.session_identifier,
				dest_x = migrationdata.x,
				dest_y = migrationdata.y,
				dest_z = migrationdata.z,
            } or nil
            SerializeUserSession(player)
        end
        player:Remove()
        if migrationdata ~= nil then
            TheShard:StartMigration(migrationdata.player.userid, migrationdata.worldid)
        end
    else
        player:DoStaticTaskInTime(0, PlayerRemove, deletesession, migrationdata, true)
    end
end

local function OnPlayerDespawn(inst, player, cb)
    player.components.playercontroller:Enable(false)
    player.components.locomotor:StopMoving()
    player.components.locomotor:Clear()

    --Portal FX
    local fx = SpawnPrefab("spawn_fx_medium_static")
    if fx ~= nil then
        fx.Transform:SetPosition(player.Transform:GetWorldPosition())
    end

    --After colour tween, remove player via task, because
    --we don't want to remove during component update loop
    -- player.components.colourtweener:StartTween({ 0, 0, 0, 1 }, 13 * FRAMES, cb or PlayerRemove, true)
end

---@type data_keyhandler[]
local data = {
    -- {
    --     namespace = 'webber_the_trainer',
    --     skillid = 'test',
    --     type = 'down',
    --     key = 'KEY_L',
    --     skill_template_type = 'none',
    --     -- client_fn_before = function (player)
    --     --     local x,z = 400,400
    --     --     for i = x-25,x+25,5 do
    --     --         for j = z-25,z+25,5 do
    --     --             SpawnPrefab('goldnugget').Transform:SetPosition(i,0,j)
    --     --             player.player_classified.MapExplorer:RevealArea(i ,0, j)
    --     --         end
    --     --     end
    --     -- end,
    --     client_rpc_data = function (player)
    --         local x,_,z = ConsoleWorldPosition():Get()
    --         -- ThePlayer:DoTaskInTime(1.5,function ()
    --         --     ThePlayer.HUD.webbert_life_panel:_createPlayerList()
    --         -- end)

    --         -- TheSim:GetPersistentString("webbert_life", function(load_success, data)
    --         --     if load_success and data ~= nil then
    --         --         local status, _data = pcall( function() return json.decode(data) end )
    --         --         if status and _data then
    --         --             for k,v in pairs(_data) do
    --         --                 print(k,v)
    --         --             end
    --         --         end
    --         --     end
    --         -- end)
            
    --         return x,z
    --     end,
    --     fn = function (player)
    --         -- local tx,ty = TheWorld.Map:GetTileCoordsAtPoint(x,y,z)
    --         -- TheWorld.Map:SetTile(tx,ty,11)
    --         -- TheWorld.Map:RebuildLayer(11,tx,ty)
    --         -- TheWorld.Map:RebuildLayer(11,tx,ty)

    --         -- local staff = player.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
    --         -- if staff and staff.components.staff_arachnidnexus_bind then
    --         --     -- for i = 1,200 do
    --         --         local bug = SpawnPrefab('webbert_skitter')
    --         --         bug.Transform:SetPosition(x,y,z)
    --         --         bug.AnimState:HideSymbol("red_art")
    --         --         bug.components.webbert_skitter_misc:ExchangeHead(false,'meat','meat','raw')


    --         --         staff.components.staff_arachnidnexus_bind:AddOneChild(bug)
    --         --     -- end

    --         -- end

    --         -- local x,z = 400,400
    --         -- for i = x-25,x+25,5 do
    --         --     for j = z-25,z+25,5 do
    --         --         SpawnPrefab('goldnugget').Transform:SetPosition(i,0,j)
    --         --         player.player_classified.MapExplorer:RevealArea(i ,0, j)
    --         --     end
    --         -- end
    --         -- local x,z = 400,400
    --         -- for i = 0,360,30 do
    --         --     local nx,nz = COORDS_webber_the_trainer:findPointOnCircle(x,z,25,1,i)
    --         --     player.player_classified.MapExplorer:RevealArea(nx ,0, nz)
    --         -- end
    --         -- SpawnPrefab('wortox').Transform:SetPosition(x,y,z)
    --         -- SpawnPrefab('wilson').Transform:SetPosition(x,y,z)
    --         -- SpawnPrefab('webber').Transform:SetPosition(x,y,z)
    --         -- SpawnPrefab('wendy').Transform:SetPosition(x,y,z)
    --         -- SpawnPrefab('wathgrithr').Transform:SetPosition(x,y,z)
    --         -- SpawnPrefab('willow').Transform:SetPosition(x,y,z)
    --         -- SpawnPrefab('waxwell').Transform:SetPosition(x,y,z)
    --         -- SpawnPrefab('wx78').Transform:SetPosition(x,y,z)





    --     end
    -- },
    {
        namespace = 'webber_the_trainer',
        skillid = 'test2',
        type = 'down',
        key = 'KEY_L',
        skill_template_type = 'none',
        fn = function (player, ...)
            for k, v in pairs(WORLD_TILES) do
                print(k,v)
            end
        end
    }
}


return data